package cn.hy.mygame.entity;

import android.R.integer;
import android.graphics.Canvas;
import android.graphics.Paint;
import cn.hy.mygame.global.Config;
import cn.hy.mygame.model.BaseModel;
import cn.hy.mygame.view.GameView;

public class Zombie extends BaseModel {
	private int locationX;
	private int locationY;
	private boolean isAlive;
	private int currentIndexFrame = 0;
	private int speed = 5;
	private int raceWay;
	
	public Zombie (int locationX, int locationY, int raceWay) {
		this.locationX = locationX;
		this.locationY = locationY;
		this.raceWay = raceWay;
		isAlive = true;
	}
	
	@Override
	public void drawSelf(Canvas canvas, Paint paint) {
		if (isAlive) {
			locationX -= speed;
			canvas.drawBitmap(Config.zombieFrames[currentIndexFrame], locationX, locationY, paint);
			currentIndexFrame = ((++currentIndexFrame) % 7);
			checkCollision();
			if (locationX < 0) {
				isAlive = false;
			}
		}
	}

	public int getLocationX() {
		return locationX;
	}

	public void setLocationX(int locationX) {
		this.locationX = locationX;
	}

	public int getLocationY() {
		return locationY;
	}

	public void setLocationY(int locationY) {
		this.locationY = locationY;
	}

	public boolean isAlive() {
		return isAlive;
	}

	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}
	
	private void checkCollision () {
		GameView.getInstance().checkCollision(this, raceWay);
	}
	
	@Override
	public int getModelWidth() {
		// TODO Auto-generated method stub
		return Config.zombieFrames[0].getWidth();
	}
}
